<?xml version="1.0"?>
<OnTheFlyInstruction xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <InstanceId>SPCTypeInfoSample</InstanceId>
  <CustomAppConfig />
  <Tags>
    <string>SharePoint</string>
  </Tags>
  <AdditionalAssemblies />
  <Code><![CDATA[// Gets a table of content type basic info
// and the schema of one content type

// v 1.0 - 2013_07_02 - rev 0

using System;using xSolon.Instructions.DTO;
using System.Linq;using System.Data;
using xSolon.Instructions;using System.Collections.Generic;
using Microsoft.SharePoint;using System.Xml;
using xSolon.Instructions.SP;using System.Text;

public class SPCTypeInfoSample : AbstractInstruction
{

	public override void Run()
	{

		using (var site = new SPSite("http://localhost"))
		using (var web = site.OpenWeb())
		{
			// Simple serialization of cTypes
			// visible in the 'Data Table' tab
			ResultTable = web.AvailableContentTypes.GetSerializedList().ListToTable();
			
			var schema = web.AvailableContentTypes["Audio"].SchemaXml.GetXmlDocument();
			
			// schema visible in 'Result' tab
			Response = Beautify(schema);
			
		}

	}

	// formats xml document
	static public string Beautify(XmlDocument doc)
	{//http://stackoverflow.com/questions/203528/what-is-the-simplest-way-to-get-indented-xml-with-line-breaks-from-xmldocument
	    StringBuilder sb = new StringBuilder();
	    XmlWriterSettings settings = new XmlWriterSettings();
	    settings.Indent = true;
	    settings.IndentChars = "  ";
	    settings.NewLineChars = "\r\n";
	    settings.NewLineHandling = NewLineHandling.Replace;
	    using (XmlWriter writer = XmlWriter.Create(sb, settings)) {
	        doc.Save(writer);
	    }
	    return sb.ToString();
	}
	
}]]></Code>
</OnTheFlyInstruction>